package com.piece.admin.model;

import com.piece.core.framework.annotation.translate.DicTranslate;
import com.piece.core.framework.support.model.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Entity
@NoArgsConstructor
@Table(name = "tb_sys_menu")
@ApiModel(value = "菜单权限表: tb_sys_menu")
public class TbSysMenu extends BaseEntity implements Serializable {

    @Id
    @Column(name = "menu_id", length = 11)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "主键")
    private Long menuId;

    @Column(name = "menu_name", length = 50)
    @ApiModelProperty(value = "菜单名称")
    private String menuName;

    @Column(name = "parent_id", length = 11)
    @ApiModelProperty(value = "父菜单ID")
    private Long parentId;

    @Transient
    @ApiModelProperty(value = "父菜单名称")
    private String parentName;

    @Column(name = "order_num", length = 4)
    @ApiModelProperty(value = "显示顺序")
    private String orderNum;

    @Column(name = "path", length = 200)
    @ApiModelProperty(value = "请求地址")
    private String path;

    @Column(name = "redirect", length = 200)
    @ApiModelProperty(value = "重定向地址")
    private String redirect;

    @Column(name = "component", length = 200)
    @ApiModelProperty(value = "组件名称")
    private String component;

    @Column(name = "target", length = 10)
    @ApiModelProperty(value = "打开方式", notes = "default,_blank")
    private String target;

    @Column(name = "menu_type", length = 1)
    @ApiModelProperty(value = "菜单类型", notes = "N导航 M目录 C菜单 B按钮")
    private String menuType;

    @Transient
    @ApiModelProperty(value = "菜单类型名称")
    private String menuTypeName;

    @Column(name = "visible", length = 1)
    @ApiModelProperty(value = "菜单状态", notes = "0显示 1隐藏")
    private String visible;

    @Transient
    @DicTranslate(source = "visible", dicType = "sys_show_hide")
    @ApiModelProperty(value = "菜单状态名称")
    private String visibleName;

    @Column(name = "perms", length = 100)
    @ApiModelProperty(value = "权限标识")
    private String perms;

    @Column(name = "icon", length = 100)
    @ApiModelProperty(value = "菜单图标", notes = "默认#")
    private String icon;

    @Column(name = "remark", length = 500)
    @ApiModelProperty(value = "备注")
    private String remark;

    @Transient
    @ApiModelProperty(value = "是否有子菜单")
    private boolean hasChildren;

    @Transient
    @ApiModelProperty(value = "子菜单")
    private List<TbSysMenu> children = new ArrayList<>();
}
